use std::io::prelude::*;
use std::io::{self, BufWriter, Write};
use std::thread::sleep;
use std::time::Duration;

pub fn progress1() {
    let mut _str: [char; 101] = [' '; 101];
    let nchar: [char; 4] = ['-', '\\', '|', '/'];
    let mut sw = BufWriter::new(io::stdout());
    for progress_v in 0..=100 {
        // 注意 /r xxxx 和 xxxx /r的区别： 前者是先定位到行头再输出xxxx， 后者则是先输出xxxx，再定位到行头。
        // 前者再mac osx上能正确地看到输出，后者则一直不显示输出。
        // sw.write_fmt(format_args!("\r{}",'['));
        // _str[progress_v] = '#';
        // for i in _str.iter(){
        //     sw.write_fmt(format_args!("{}", i));
        // }
        // sw.write_fmt(format_args!("{}", ']'));
        let _ = sw.write_fmt(format_args!("\r\t[{}]下载中~", nchar[progress_v % 4]));
        sw.flush();
        sleep(Duration::from_millis(400));
    }
    println!("{}", "hahah");
}
